package view.parameterpanels;

import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;

import net.miginfocom.swing.MigLayout;
import view.CenterTabbedPane.EBenchmarkTab;
import view.EBenchmarkPanel;

/**
 * The view class {@code OutputParameterPanel} draws a standard panel
 * that can be used for output parameters. It shows basic parameter information.
 * @author Oliver Eckstein
 *
 */
public class OutputParameterPanel extends EBenchmarkPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	
	/**
	 * The title that gives the user a description of the panel.
	 */
	protected JLabel title;
	
	/**
	 * The most important part of a {@code ParameterPanel}. On this panel
	 * all important parameter information is drawn.
	 */
	protected JPanel paramPanel;
	
	/**
	 * To create a new {@code OutputParameterPanel}.
	 * @param logoPath a path to an optional logo. If passed {@code null} a
	 * standard logo is used.
	 * @param tab the type of input parameters that is displayed on the panel. 
	 * @param panelTitle the panel's title.
	 */
	public OutputParameterPanel(
			String logoPath,
			EBenchmarkTab tab,
			String panelTitle) {
		super(logoPath, tab);
		this.setName(panelTitle);
		init();
	}

	/**
	 * To initiate the panel and add components.
	 */
	private void init() {
		title = new JLabel("Ergebnisdarstellung");		
		paramPanel = new JPanel();
		paramPanel.setLayout(new MigLayout());
		
		this.setLayout(new MigLayout());
		this.add(title, "wrap");		
		this.add(paramPanel);
		this.add(logo, "aligny top");
	}
	
	/**
	 * To add a parameter set to this panel.
	 @param paramInfo the parameters' information:<br>
     * paramInfo[0] = parameter's name<br>
     * paramInfo[1] = parameter's abbreviation<br>
     * paramInfo[2] = parameter's unit<br>
     * paramInfo[3] = parameter's initial value.
     * @param borderTitle the parameters' description.
     */
	public void addParameterSet(List<String[]> paramInfo, String borderTitle) {		
		JPanel parameterPanel = new JPanel(new MigLayout("wrap 4"));
        parameterPanel.setBorder(BorderFactory
                .createTitledBorder(borderTitle));
        
        // Iterate through every parameter of this set.
        for(String[] parameter : paramInfo) {
            parameterPanel.add(new JLabel(parameter[0]));            
            parameterPanel.add(new JLabel(parameter[1]));
            parameterPanel.add(new JLabel(parameter[2]));
            parameterPanel.add(new JLabel(parameter[3]));                
        }
        paramPanel.add(parameterPanel, "wrap");
        paramPanel.revalidate();
	}

	@Override
	public void update() {
		// Nothing to do here.
	}
	
	/**
	 * To get the parameter panel from this panel.
	 * @return the parameter panel.
	 */
	public JPanel getParameterPanel() {
		return paramPanel;
	}
}
